<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>WebSocket</title>
</head>
<body>
<h1>WebSocket 示例</h1>
<input id="con" name="con" value/>
<input id="port" name="port" value/>
<button onclick="connection()">连接服务</button>
<p/>
<input id="wsmsg" name="wsmsg" value='{"send":"","receive":"","message":"","type":""}'/>
<button onclick="submitWs()">Submit</button>
</body>
<script>
    function getUrl(port,id){
      return "ws://localhost:"+port+"/brick/ws/demo/"+id;
    }
	var ws=null;
	function connection(){
	   var name = document.getElementById("con").value;
	   var port = document.getElementById("port").value;
	   ws=new WebSocket(getUrl(name,port));
	   ws.onopen=function(){
		    alert("started")
        }
        ws.onmessage=function(e){
          alert("onmessage:"+e.data);
        }
        ws.onclose=function(){
            alert("closed")
        }
	}
	function submitWs(){
	    console.log("submitWs method")
	    var msg = document.getElementById("wsmsg").value;
	    ws.send(msg);
	}

</script>
</html>
